package cn.czxy.web.servlet.flie;

import cn.czxy.domain.User;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhangyuan@163.com
 * @date 2019/4/13
 * @infos
 */
public class LoginFilter implements Filter {

    public void init(FilterConfig config) throws ServletException {

    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        User user = (User) request.getSession().getAttribute("user");
        if (user==null)
        {
            //没有登录
            request.setAttribute("msg","请先登录");
            response.sendRedirect(request.getContextPath()+"/demand/overTime.jsp");
        }
        else{
            chain.doFilter(req, resp);
        }
    }

    public void destroy() {

    }

}
